package com.ruoyi.web.controller.system;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Appmanager;
import com.ruoyi.system.domain.Apptype;
import com.ruoyi.system.domain.Drtypemode;
import com.ruoyi.system.service.IAppmanagerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DrllInfo;
import com.ruoyi.system.service.IDrllInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 驱动类型Controller
 * 
 * @author yaozh
 * @date 2024-02-24
 */
@RestController
@RequestMapping("/system/drllinfo")
public class DrllInfoController extends BaseController
{
    @Autowired
    private IDrllInfoService drllInfoService;
    @Autowired
    private IAppmanagerService appManagerService;

    /**
     * 查询驱动类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:drllinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrllInfo drllInfo,@RequestParam String dbName)
    {
        List<Appmanager> appList = appManagerService.selectAppManagerListByUserAndDbName(getLoginUser(),dbName);
        if(appList == null || appList.size() == 0){
            return getDataTable(new ArrayList<>());
        }
        startPage();
        List<DrllInfo> list = drllInfoService.selectDrllInfoList(drllInfo,dbName);
        return getDataTable(list);
    }

    /**
     * 不分页，查询驱动列表
     */
    @PreAuthorize("@ss.hasPermi('system:drllinfo:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(@RequestParam String dbName)
    {
        List<Appmanager> appList = appManagerService.selectAppManagerListByUserAndDbName(getLoginUser(),dbName);
        if(appList == null || appList.size() == 0){
            return success(new ArrayList<>());
        }
        return success(drllInfoService.selectDrllInfoForAll(dbName));
    }

    /**
     * 导出驱动类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:drllinfo:export')")
    @Log(title = "驱动类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrllInfo drllInfo,@RequestParam String dbName)
    {
        List<Appmanager> appList = appManagerService.selectAppManagerListByUserAndDbName(getLoginUser(),dbName);
        List<DrllInfo> list = new ArrayList<>();
        if(appList != null && appList.size() > 0){
            list = drllInfoService.selectDrllInfoList(drllInfo,dbName);
        }
        ExcelUtil<DrllInfo> util = new ExcelUtil<DrllInfo>(DrllInfo.class);
        util.exportExcel(response, list, "驱动类型数据");
    }

    /**
     * 获取驱动类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:drllinfo:query')")
    @GetMapping(value = "/{drllid}")
    public AjaxResult getInfo(@PathVariable("drllid") Long drllid,@RequestParam String dbName)
    {
        return success(drllInfoService.selectDrllInfoByDrllid(drllid,dbName));
    }

    /**
     * 新增驱动类型
     */
    @PreAuthorize("@ss.hasPermi('system:drllinfo:add')")
    @Log(title = "驱动类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrllInfo drllInfo,@RequestParam String dbName)
    {
        return toAjax(drllInfoService.insertDrllInfo(drllInfo,dbName));
    }

    /**
     * 修改驱动类型
     */
    @PreAuthorize("@ss.hasPermi('system:drllinfo:edit')")
    @Log(title = "驱动类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrllInfo drllInfo,@RequestParam String dbName)
    {
        return toAjax(drllInfoService.updateDrllInfo(drllInfo,dbName));
    }

    /**
     * 删除驱动类型
     */
    @PreAuthorize("@ss.hasPermi('system:drllinfo:remove')")
    @Log(title = "驱动类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{drllids}")
    public AjaxResult remove(@PathVariable Long[] drllids,@RequestParam String dbName)
    {
        return toAjax(drllInfoService.deleteDrllInfoByDrllids(drllids,dbName));
    }
}
